package com.pgybook.db.entity.mapper;

import org.springframework.stereotype.Repository;
import com.pgybook.db.entity.domain.Library;
import com.pgybook.db.entity.domain.LibraryEx;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

@Repository
public interface LibraryMapper {
    int countByExample(LibraryEx example);

    int deleteByExample(LibraryEx example);

    @Delete({
            "delete from library",
            "where LIBID = #{libid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer libid);

    @Insert({
            "insert into library (NAME, CONTACT, ",
            "PHONE, ADDRESS, ",
            "STATUS, DESCRIPTION, ",
            "CRTTIME, UPDTIME)",
            "values (#{name,jdbcType=VARCHAR}, #{contact,jdbcType=VARCHAR}, ",
            "#{phone,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, ",
            "#{status,jdbcType=INTEGER}, #{description,jdbcType=VARCHAR}, ",
            "#{crttime,jdbcType=TIMESTAMP}, #{updtime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "libid", before = false, resultType = Integer.class)
    int insert(Library record);

    int insertSelective(Library record);

    List<Library> selectByExample(LibraryEx example);

    @Select({
            "select",
            "LIBID, NAME, CONTACT, PHONE, ADDRESS, STATUS, DESCRIPTION, CRTTIME, UPDTIME",
            "from library",
            "where LIBID = #{libid,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    Library selectByPrimaryKey(Integer libid);

    int updateByExampleSelective(@Param("record") Library record, @Param("example") LibraryEx example);

    int updateByExample(@Param("record") Library record, @Param("example") LibraryEx example);

    int updateByPrimaryKeySelective(Library record);

    @Update({
            "update library",
            "set NAME = #{name,jdbcType=VARCHAR},",
            "CONTACT = #{contact,jdbcType=VARCHAR},",
            "PHONE = #{phone,jdbcType=VARCHAR},",
            "ADDRESS = #{address,jdbcType=VARCHAR},",
            "STATUS = #{status,jdbcType=INTEGER},",
            "DESCRIPTION = #{description,jdbcType=VARCHAR},",
            "CRTTIME = #{crttime,jdbcType=TIMESTAMP},",
            "UPDTIME = #{updtime,jdbcType=TIMESTAMP}",
            "where LIBID = #{libid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Library record);
}
